package com.md24housecall.adapter;

import android.annotation.SuppressLint;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.md24housecall.fragment.HelpFragment;
import com.md24housecall.fragment.HomeFragment;
import com.md24housecall.fragment.MultiIHealthFragment;
import com.md24housecall.fragment.PartnerFragment;
import com.md24housecall.fragment.PatientFragment;
import com.md24housecall.fragment.RequestCallFragment;
import com.md24housecall.util.GlobalConstant;
import com.md24housecall.util.MyLog;

@SuppressLint("DefaultLocale")
public class FragmentAdapter extends FragmentStatePagerAdapter {
	private static String[] arrayContent;
//	private Utils util = Utils.getInstance();
	private GlobalConstant constant=GlobalConstant.getInstance();
	private String code = "";

	public FragmentAdapter(FragmentActivity act,String[]contents) {
		super(act.getSupportFragmentManager());
//		this.code = util.getCode(act);
		this.code=constant.code;
//		constant.userType=util.getUserType(act);
		MyLog.d(GlobalConstant.TAG,"constant.userType: "+constant.userType);
		arrayContent=contents;
		//DucNM:load fragment request a call replace home fragment
//		if(!code.equals("")){
////			CONTENT[0]=act.getResources().getString(R.string.act_request_call);
//			CONTENT = act.getResources().getStringArray(R.array.tabs_name_login);
//			if(constant.userType==constant.CENTER_USER)
//				CONTENT[CONTENT.length-1]=act.getResources().getString(R.string.center_tab_name);
//			constant.code=code;
//		}else{
//			CONTENT = act.getResources().getStringArray(R.array.tabs_name);
//		}
//		notifyDataSetChanged();
		//DucNM:load fragment request a call replace home fragment
	}

	@Override
	public Fragment getItem(int position) {
		switch (position) {
			case 0:
				if(!code.equals(""))
					return RequestCallFragment.newInstance(position);
				//DucNM:load fragment request a call replace home fragment
				return HomeFragment.newInstance(position);
			case 1:
				return HelpFragment.newInstance(position);
			case 2:
				return PartnerFragment.newInstance(position);
//			case 3:
//				return FibroDiagnosticFragment.newInstance(position);
			case 3:
//				return IHealthFragment.newInstance(position);
				if(constant.userType==constant.SINGLE_USER)
					return MultiIHealthFragment.newInstance(position);
				else if(constant.userType==constant.CENTER_USER)
					return PatientFragment.newInstance(position);
			default:
				return HomeFragment.newInstance(position);
		}
	}

	@Override
	public CharSequence getPageTitle(int position) {
		return arrayContent[position % arrayContent.length].toUpperCase();
	}

	@Override
	public int getCount() {
//		MyLog.d(GlobalConstant.TAG, "CONTENT.length: "+arrayContent.length);
		return arrayContent.length;
	}

	public static String getTabTitle(int position) {
		return arrayContent[position % arrayContent.length].toUpperCase();
	}
}
